<?php
/**
 * Model for the roles table
 */
class Roles extends CI_Model
{
	public function __construct()
	{
		$this->load->database();
	}
	
	public function select_all()
	{
		$this->db->from('roles');
		$query = $this->db->get();
		return $query->result_array();
	}
	
	public function select_by_id($id)
	{
		$this->db->from('roles');
		$this->db->where('id', $id);
		$query = $this->db->get();
		return ($query->num_rows() > 0) ? $query->row() : null;
	}
	
	public function select_by_name($name)
	{
		$this->db->from('roles');
		$this->db->where('name', $name);
		$query = $this->db->get();
		return ($query->num_rows() > 0) ? $query->row() : null;
	}
	
	public function select_by_names($names)
	{
		$this->db->from('roles');
		$this->db->where_in('name', $names);
		$query = $this->db->get();
		return $query->result_array();
	}
	
	public function select_by_user_id($user_id)
	{
		$this->db->from('roles');
		$this->db->join('users', 'roles.id = users.role_id');
		$this->db->where('users.id', $user_id);
		$query = $this->db->get();
		return ($query->num_rows() > 0) ? $query->row() : null;
	}
}